package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author diva
 * @date 2025/10/13 20:22
 * @ProjectName 
 *
 */
@Slf4j
@RestController
@RequestMapping("/clues")
public class ClueController {
    @Autowired
    private ClueService clueService;
    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO dto) {
        clueService.addClue(dto);
        return Result.success();
    }
    @GetMapping
    public Result list(ClueListDTO dto){
        PageResult<ClueDO> result = clueService.clueList(dto);
        return Result.success(result);
    }
    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable("clueId") Integer clueId, @PathVariable("userId") Integer userId) {
        clueService.updateById(ClueDO.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable("id") Integer id) {
        ClueVO vo = clueService.getClueInfoById(id);
        return Result.success(vo);
    }
    @LogAnno
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto){
        log.info("==============Controller中的updateClueInfoById处理线程名称是={}",Thread.currentThread().getName());
        clueService.updateClueInfoById(dto);
        return Result.success();
    }
    @LogAnno
    @PutMapping("toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id){
        clueService.toBusiness(id);
        return Result.success();
    }
    @LogAnno
    @GetMapping("/pool")
    public Result CluePool(CluePoolDTO dto){
        PageResult<Clue> result = clueService.cluePool(dto);
        return Result.success(result);
    }
    @LogAnno
    @PutMapping("/false/{id}")
    public Result toFalse(@PathVariable Integer id, @RequestBody MarkFalseClueDto dto){
        clueService.toFalse(id, dto);
        return Result.success();
    }
}
